package com.mymusic;


import android.content.ContentUris;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
/**
 * A dummy fragment representing a section of the app, but that simply displays dummy text.
 */
public   class AlbumFragment extends Fragment implements OnClickListener {

    public static final String ARG_OBJECT = "object";
   // private Context context;
    private Long selectedAlbumId;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	// TODO Auto-generated method stub
    	super.onCreate(savedInstanceState);
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_album, container, false);
        
        Uri sArtworkUri = Uri
                .parse("content://media/external/audio/albumart");
        Bundle args = getArguments();
        selectedAlbumId=Long.parseLong(args.getString("albumId"));
        Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri,selectedAlbumId);

        Log.d("albumArtUri=>",albumArtUri.toString());
       // context=inflater.getContext();
       /* Bitmap bitmap = null;
        context=inflater.getContext();
        try {
            bitmap = MediaStore.Images.Media.getBitmap(
            		context.getContentResolver(), albumArtUri);
            bitmap = Bitmap.createScaledBitmap(bitmap, 30, 30, true);

        } catch (FileNotFoundException exception) {
            exception.printStackTrace();
            bitmap = BitmapFactory.decodeResource(context.getResources(),
                    R.drawable.audio_file);
        } catch (IOException e) {

            e.printStackTrace();
        }*/
        ImageView imageView=((ImageView) rootView.findViewById(android.R.id.text1)) ;
        imageView.setImageURI(albumArtUri);
        imageView.setOnClickListener(this);
        /*((TextView) rootView.findViewById(android.R.id.text1)).setText(
                Integer.toString(args.getInt(ARG_OBJECT)));*/
        
        return rootView;
    }

	@Override
	public void onClick(View v) {
		 switch (v.getId()) {
	        case android.R.id.text1:
	        	Intent intent = new Intent(v.getContext(),AlbumActivity.class);
				intent.putExtra("albumId",selectedAlbumId);
				startActivity(intent);
		 }
		
	}
    

}